home *** CD-ROM | disk | FTP | other *** search
-
- 9:MATHS FUNCTIONS
-
- AMOS Basic includes a wide variety of the more commonly needed
- mathematical functions. To conserve memory, AMOS uses the standard
- Amiga library routines. The appropriate libraries will be loaded
- automatically from your workbench disc the first time you call one of
- these functions in a particular session. You should therefore ensure
- that the current disc contains the file MATHTRANS.LIBRARY in the LIBS
- folder.
-
- Trigonometric functions
- The trigonometric functions provide you with a useful array of
- mathematical tools. These can be used for a variety of purposes, from
- education to the creation of complex musical wabeforms.
-
- DEGREE (use degrees)
-
- DEGREE
-
- Generally all angles are specified in radians. Since radians are rather
- difficult to work with, it's possible to instruct AMOS to accept angles
- in degrees. Once you've activated this feature any subsequent calls to
- the trig functions will expect you to use degrees.
-
- RADIAN (use radian measure)
-
- RADIAN
-
- THe RADIAN directive informs AMOS that all future angles are to be
- entered using radians - this is the default.
-
- =PI# (a constant PI)
-
- a#=PI#
-
- This function returns the number called PI which represents the result
- of the division of the diameter of a circle by the circumference. PI is
- used by most of the trigonometric functions to calculate angels. Note
- that a # character is part of the token name! This is to avoid clashes
- with your own variable names.
-
- =SIN (sine)
-
- s#=SIN(a)
- s#=SIN(a#)
-
- The SIN functions calculates the sine of the angle in n. Note that the
- function always returns a floating point number.
-
- =COS (cosine)
- c#=COS(a[#])
-
- The cosine function computes the cosine of an angle.
-
- =TAN (tangent)
-
- t#=TAN(a[#])
-
- TAN generates the tangent of an angle.
-
- =ACOS (arc cos)
-
- c#=ACOS(n#)
-
- The ACOS function takes a number between -1 and +1 and calculates the
- angle which would be needed to generate this value with COS.
-
- Note, we haven't provided you with ASIN, because it's not really
- needed. It can be readily computed using the formula:
-
- ASIN(X)=90-ACOS(X) : Rem Measured in degrees.
- ASIN(X)=1.5708-ACOS(X) : Rem using radians
-
- =ATAN (arc tangent)
-
- t#=ATAN(n#)
-
- ATAN returns the arctan of a number.
-
- =HSIN (hyperbolic sine)
-
- s#=HSIN(a[#])
-
- HSIN computes the hyperbolic sine of angle a.
-
- =HCOS (hyperbolic cosine)
-
- c#=HCOS(a[#])
-
- HCOS calculates the hyperbolic cosine of angle a.
-
- =HTAN (hyperbolic tangent)
-
- t#=HTAN(a[#])
-
- HTAN returns the hyperbolic tangent of the angle a.
-
- Standard mathematical functions
-
- =LOG (logarithm)
-
- r#=LOG(v[#])
-
- LOG returns the logarithm in base 10 (log 10) of the expression in v#.
-
- =EXP (exponential function)
-
- r#=EXP(e#)
-
- Calculates the exponential of e#. Example:
-
- Print Exp(1)
- ( result : 2.71828 )
-
- =LN (natural logarithm)
-
- r#=LN(l#)
-
- LN computes the natural of naperian logarithm of l#.
-
- =SQR (square root)
-
- s#=SQR(v[#])
-
- SQR calculates the square root of a number.
-
-
-
- r=ABS(v[#])
-
- ABS returns the absolute value of v, taking no account of its sign.
-
- =INT (convert floating point number to an integer)
-
- i=INT(v#)
-
- INT rounds a floating point number in v down to the nearest whole
- integer.
-
- =SGN (find the sign of a number)
-
- s=SGN(v[#])
-
- SGN returns a value of representing the sign of a number. There are
- three possibilities.
-
- -1, if v is negative
- 0, if v is zero
- 1, if v is positive
-
- Creating random sequences
-
- =RND (random number generation)
-
- RND generates a random integer between 0 and n inclusive. But if n is
- less than zero, RND will return the last value it produced. This can be
- very useful when debugging one of your programs.
-
- RANDOMIZE (set the seed of a random number)
-
- RANDOMIZE seed
-
- In practice, the numbers produced by the RND function are not really
- random. They're computed internally using a complex mathematical
- formula. The starting point for this calculation is taken from a number
- known as the "seed". This seed is set to a standard value whenever you
- load AMOS Basic into the computer. So the sequence of numbers generated
- by RND will be exactly the same every time you run your game!
-
- The RANDOMIZE command allows you to set the seed value directly, so
- that the numbers would really look like random every time.
-
- "seed" can be any value you wish. In order to generate a true random
- numbers, you need some way of varying the seed from game to game. This
- can be achieved using the TIMER instruction:
-
- Randomize Timer
-
- TIMER is a Basic function which returns the amount of time which has
- elapsed since your Amiga was switched on in the current session. All
- timings are measured in units of a 50th of a second.
-
- Manipulating numbers
-
- =MAX (get the maximum of two values)
-
- r=MAX(x,y)
- r#=MAX(x#,y#)
- r$=MAX(x$,y$) MAX compares two expressions and returns the largest.
- These expressions can be composed of numbers or
- strings of characters, providing you don't try to mix different types
- of expressions in one instruction.
-
- Print Max(10,4)
- ( result : 10 )
-
- =MIN (return the minimum of two values)
-
- r=MIN(x,y)
- r#=MIN(x#,y#)
- r$=MIN(x$,y$) This works the same way the =MAX does, except returns
- the minimum value of compared numbers/strings.
-
- SWAP (swap the contents of two variables)
-
- SWAP x,y
- SWAP x#,y#
- SWAP x$,y$ Swaps the data between any two variables of the same
- type.
-
- FIX (set precision of floating point output)
-
- FIX(n)
-
- Changes the way your floating point numbers will be displayed on the
- screen or printer. There are four possibilities.
-
- If 0<n<16 then n denotes the number of figures to be output after
- the decimal point.
- If n> 16 the printout will be proportional and any trailing zeros will
- be removed.
- If n<0 Then all floating point numbers will be displayed in
- exponential format, and the absolute value of n will
- determine the number of digits after the decimal point.
-
- If n=16 then the format will be returned to normal
-
- Fix(-4) : Print PI#
-
- DEF FN (create a user-defined function)
-
- DEF FN name [(list)]=expression
-
- The DEF FN command lets you create your own user-defined functions
- within an AMOS Basic program. These can be used to compute commonly
- needed values quickly and easily.
-
- "nane" is the name of the function you wish to define. "list" is a
- set of variables separated by commas. Only the type of these variables
- is significant. When you call your function, any variables you enter
- with, will be automatically subsituted in the appropriate positions.
-
- "expression" can include any of the standard AMOS functions you wish.
- Like all Basic expressions, it's limited just to a single line of prog.
-
- FN (call a user-defined function)
-
- FN name [(variable list)]
-
- FN executes a function defined using DEF FN. Example:
-
- Def Fn Asin(X)=90-Acos(X)
- Degree
- Print Fn Asin(0.5)
-